home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Syn Text Editor 2.1.0.46 / synsetup-2.1.0.46.exe / {app} / scripts / openfile.vbs < prev    next >
Text File  |  2003-08-13  |  4KB  |  121 lines

  1. ' Caption: Open File|
  2. ' Hint: Open File|
  3. ' Icon: openfile.ico|
  4. '
  5. '  syn
  6. '  Copyright (C) 2000-2003, Ascher Stefan. All rights reserved.
  7. '  stievie@utanet.at, http://web.utanet.at/ascherst/
  8. '
  9. '  The contents of this file are subject to the Mozilla Public License
  10. '  Version 1.1 (the "License"); you may not use this file except in compliance
  11. '  with the License. You may obtain a copy of the License at
  12. '  http://www.mozilla.org/MPL/
  13. '
  14. '  Software distributed under the License is distributed on an "AS IS" basis,
  15. '  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  16. '  the specific language governing rights and limitations under the License.
  17. '
  18. '  The Original Code is openfile.vbs, released Sun, 26 May 2002 10:55:39 UTC.
  19. '
  20. '  The Initial Developer of the Original Code is Ascher Stefan.
  21. '  Portions created by Ascher Stefan are Copyright (C) 2000-2003 Ascher Stefan.
  22. '  All Rights Reserved.
  23. '
  24. '  Contributor(s): .
  25. '
  26. '  Alternatively, the contents of this file may be used under the terms of the
  27. '  GNU General Public License Version 2 or later (the "GPL"), in which case
  28. '  the provisions of the GPL are applicable instead of those above.
  29. '  If you wish to allow use of your version of this file only under the terms
  30. '  of the GPL and not to allow others to use your version of this file
  31. '  under the MPL, indicate your decision by deleting the provisions above and
  32. '  replace them with the notice and other provisions required by the GPL.
  33. '  If you do not delete the provisions above, a recipient may use your version
  34. '  of this file under either the MPL or the GPL.
  35. '
  36. '  You may retrieve the latest version of this file at the syn home page,
  37. '  located at http://syn.sourceforge.net/
  38. '
  39. ' $Id: openfile.vbs,v 1.4.2.5 2003/08/13 00:38:45 neum Exp $
  40.  
  41.  
  42. ' assumes the selected text is a (part of a) filename and opens it, example:
  43. ' select cmnfunc and run this script. This works also with forward slashed filenames
  44. ' as found in links, so you can use it to open links with it, like syn/ver2/index.htm.
  45. ' If SelText = "" it searchs for a valid filename at the caret pos.
  46.  
  47. option explicit
  48.  
  49. ' Remove the dot to include this files
  50. '#.include <consts>
  51. '#include <cmnfunc>
  52.  
  53. dim BlankChars(13)
  54.  
  55. sub Main(dummy)
  56.   if Documents.Count = 0 then
  57.     exit sub
  58.   end if
  59.   dim s
  60.   s = ActiveDocument.SelText
  61.   if s = "" then
  62.     s = FindLink
  63.   end if
  64.   if not FileExists(s) then
  65.     s = GetAbsoluteFile(ActiveDocument.FileName, s)
  66.   end if
  67.   if (not FileExists(s)) and (ExtractFileExt(s) = "") then
  68.     s = s & ExtractFileExt(ActiveDocument.FileName)
  69.   end if
  70.   if FileExists(s) then
  71.     Documents.Open false, s, false
  72.   end if
  73. end sub
  74.  
  75. function FindLink
  76.   BlankChars(0) = "*"
  77.   BlankChars(1) = "?"
  78.   BlankChars(2) = "="
  79.   BlankChars(3) = Chr(34)
  80.   BlankChars(4) = "<"
  81.   BlankChars(5) = ">"
  82.   BlankChars(6) = ","
  83.   BlankChars(7) = ";"
  84.   BlankChars(8) = "+"
  85.   BlankChars(9) = "^"
  86.   BlankChars(10) = Chr(10)
  87.   BlankChars(11) = Chr(13)
  88.   BlankChars(12) = Chr(9)
  89.   BlankChars(13) = " "
  90.   dim x, y
  91.   dim l
  92.   x = ActiveDocument.CaretX
  93.   y = ActiveDocument.CaretY
  94.   l = ActiveDocument.Lines(y - 1)   ' 0-based
  95.   if Trim(l) = "" then exit function
  96.   dim i
  97.   dim p1, p2
  98.   p1 = x
  99.   p2 = x
  100.   while not IsBlank(Mid(l, p1, 1)) and (p1 >= 0)
  101.     p1 = p1 - 1
  102.   wend
  103.   while not IsBlank(Mid(l, p2, 1)) and (p2 <= Len(l))
  104.     p2 = p2 + 1
  105.   wend
  106.   if p1 < p2 then
  107.     FindLink = Mid(l, p1 + 1, p2 - p1 - 1)
  108.   end if
  109. end function
  110.  
  111. function IsBlank(s)
  112.   dim i
  113.   IsBlank = false
  114.   for i = 0 to UBound(BlankChars)
  115.     if s = BlankChars(i) then
  116.       IsBlank = true
  117.       exit for
  118.     end if
  119.   next
  120. end function
  121.